package com.yllt4cloud.ddauth.service.impl;


import com.yllt4cloud.common.ddbase.containers.SystemConfigContainer;
import com.yllt4cloud.common.ddbase.domain.SystemConfig;
import com.yllt4cloud.ddauth.mapper.SystemConfigMapper;
import com.yllt4cloud.ddauth.service.ISystemConfigService;
import com.yllt4cloud.ddauth.service.base.BaseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * 
 * <br>
 * <b>功能：</b>SystemConfigServiceImpl<br>
 * <b>作者：</b>Administrator<br>
 * <b>日期：</b> Fri Jan 08 10:59:11 CST 2016 <br>
 * <b>版权所有： 2016,yllt.com<br>
 */ 
@Service
@Transactional
public class SystemConfigServiceImpl extends BaseService<SystemConfig> implements ISystemConfigService {
	private final static Logger log= LoggerFactory.getLogger(SystemConfigServiceImpl.class);

	@Autowired
    private SystemConfigMapper mapper;

		
	public SystemConfigMapper getMapper() {
		return mapper;
	}
	
	@Override
	public Integer insert(SystemConfig record) {
		mapper.insert(record);
		SystemConfigContainer.instance().uptSystemConfig(record);
		return record.getId();
	}

	@Override
	public void uptSystemConfig(List<SystemConfig> configs) {
		
		//判空
		if(configs != null && !configs.isEmpty()){
			
			List<SystemConfig> list = new ArrayList<SystemConfig>();
			
			//循环更新
			for(SystemConfig systemConfig : configs){
				
				if(systemConfig.getId() == null)
					mapper.insert(systemConfig);
				else
					mapper.updateByJianMingSelective(systemConfig);
				
				list.add(systemConfig);
			}
			
			//更新成功后才可重置内存数据
			for(SystemConfig systemConfig : list){
				SystemConfigContainer.instance().uptSystemConfig(systemConfig);
			}
		}
	}
	
	
	/**
	 * 
	 * <p><b>作用：</b>根据主键部分更新</p>
	 * <p><b>日期：</b>2015-4-11 上午10:20:00</p>
	 * <p><b>作者：</b>yaozq</p>
	 * @param record
	 * @return
	 * @exception
	 */
	public int updateByPrimaryKeySelective(SystemConfig record){
		int result = getMapper().updateByPrimaryKeySelective(record);
		SystemConfigContainer.instance().uptSystemConfig(record);
		return result;
	}

	/**
	 * 
	 * <p><b>作用：</b>根据主键全部更新</p>
	 * <p><b>日期：</b>2015-4-11 上午10:20:04</p>
	 * <p><b>作者：</b>yaozq</p>
	 * @param record
	 * @return
	 * @exception
	 */
	public int updateByPrimaryKey(SystemConfig record){
		int result = getMapper().updateByPrimaryKey(record);
		SystemConfigContainer.instance().uptSystemConfig(record);
		return result;
	}

	@Override
	public void uptOrInsertBatch(List<SystemConfig> list) {
		mapper.uptOrInsertBatch(list);
		SystemConfigContainer.instance().uptSystemConfig(list);
	}

	@Override
	public Integer uptOrInsert(SystemConfig systemConfig) {
		mapper.uptOrInsert(systemConfig);
		SystemConfigContainer.instance().uptSystemConfig(systemConfig);
		return systemConfig.getId();
	}
	
	/**
	 * 根据简名获取 系统设置信息
	 * @param jianMing 简名
	 * @return 系统设置信息
	 */
	public SystemConfig selectByPrimaryJianMing(String jianMing){
		return mapper.selectByPrimaryJianMing(jianMing);
	}


	public int queryByCount(Map<String, Object> paramMap){
		return mapper.queryByCount(paramMap);
	}

    /**
     * 根据简名更新系统设置信息
     */
    public int updateByJianMingSelective(SystemConfig systemConfig){
        return mapper.updateByJianMingSelective(systemConfig);
    }
}
